package demoCode;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import lombok.AllArgsConstructor;
import lombok.Getter;

public enum DepOrgLevelEnum {

    C1("c1", 1),
    C2("c2", 2),
    C3("c3", 3),

    L1("l1", 21),
    L2("l2", 22),
    L3("l3", 23),
    L4("l4", 24),
    L5("l5", 25),
    ;

    DepOrgLevelEnum(String code, int sort) {
        this.code = code;
        this.sort = sort;
    }

    private static final Map<String, DepOrgLevelEnum> MAP = Arrays.stream(values())
            .collect(Collectors.toMap(DepOrgLevelEnum::getCode, Function.identity()));
    private final String code;

    private final int sort;

    public static DepOrgLevelEnum of(String code) {
        return MAP.get(code);
    }

    public static int sort(String code) {
        DepOrgLevelEnum of = of(code);
        if (of != null) {
            return of.getSort();
        }
        return -100;
    }

    public String getCode() {
        return code;
    }

    public int getSort() {
        return sort;
    }
}
